package com.huang.lesson05;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class UdpReceive {
    public static void main(String[] args) throws Exception {
        DatagramSocket socket = new DatagramSocket(8081);

        //准备接受包裹
        while (true){
            byte[] bytes = new byte[1024];
            DatagramPacket packet = new DatagramPacket(bytes,0,bytes.length);
            socket.receive(packet);

            String data = new String(packet.getData(), 0, packet.getData().length);
            System.out.println(data);
            if(data.equals("bye")){
                break;
            }

        }


        socket.close();
    }
}
